//
//  CryptoUtil.m
//  CommonUtil
//
//  Created by sunlubo on 2017/3/16.
//  Copyright © 2017年 milanosoft. All rights reserved.
//

#import "CryptoUtil.h"
#import <CommonCrypto/CommonCrypto.h>

@implementation CryptoUtil

+ (nonnull NSString *)md5:(nonnull NSString *) content {
    unsigned int outputLength = CC_MD5_DIGEST_LENGTH;
    unsigned char output[outputLength];
    
    NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
    CC_MD2(contentData.bytes, (unsigned int)contentData.length, output);
    
    NSMutableString *resultStr = [NSMutableString stringWithCapacity:outputLength];
    for (NSUInteger i = 0; i < outputLength; i++) {
        [resultStr appendFormat:@"%02X", output[i]];
    }
    
    return [resultStr copy];
}

@end
